/*--------------------------------------------------------------------
 - File:
 - Data&Autor:
 - Introduction: 运动睡眠管理模块
   数据flash存储：每天15min一个数据，一天96个数据，存储30天，（BLOCK 2~31）
 ----------------------------------------------------------------------*/
 #ifndef	SPORT_HIS_H_
 #define	SPORT_HIS_H_
 #include "stdint.h"
 #include "string.h"
#include "sleep_quality_algorithm.h"

 typedef    uint16_t indexday_t;  
 
  typedef enum
 {
     SPORT_HIS_STATE_SPORT = 1,         //运动状态
     SPORT_HIS_STATE_SLEEP,         //睡眠状态
     SPORT_HIS_STATE_DROPOFF,       //摘下状态
     SPORT_HIS_STATE_AWAKE,         //睡眠清醒状态
 }sport_state_t;
 

void sport_his_init(void);
void sport_his_start(void);
void sport_his_stop(void);
void sport_his_drv_handle(void);
void pedometer_active_handle(uint8_t active_step);

 sport_state_t sport_get_band_state(void);
 uint32_t sport_get_present_step(void);
 uint32_t sport_get_calorie(void);
 uint32_t sport_get_distance(void);
 uint32_t sport_get_present_active(void);
 uint16_t sport_get_sport_time(void);
 uint16_t sport_get_sleep_time(void);
 uint32_t sport_get_step_freq(void);
 
 void sport_his_across_day_handle(void);
 void sport_step_add_handle(uint16_t step_inc);
 void sport_step_add_distance(uint32_t distance_inc);
 void sport_step_add_calorie(uint32_t calorie_inc);
 void sport_his_syn_from_flash(void);
 uint8_t sport_his_get_block_index(uint8_t days_ago);
 uint32_t sport_his_get_allday_info(void);
 
 void sport_his_switch_step_freq_calc(uint8_t on_off);
 uint32_t sleep_time_calc(uint8_t select_block,uint8_t start_data_index,uint8_t end_data_index);
 
 uint32_t sport_flash_data_convert(uint32_t  data);
uint8_t sport_his_sleep_statistics(uint8_t days_ago , sleep_quality_t *sleep_quality, uint16_t *master_start,uint16_t *master_end);

typedef struct
{
  uint8_t     valid_count;
  uint8_t     max_data_index;
  uint32_t    max_data;
}sport_day_detail_t;

typedef enum
{
    SPORT_FLASH_DETAIL_DATA_TYPE_STEP,
    SPORT_FLASH_DETAIL_DATA_TYPE_SPORT_TIME,
    SPORT_FLASH_DETAIL_DATA_TYPE_DISTANCE,
    SPORT_FLASH_DETAIL_DATA_TYPE_CALORIE,
}sport_flash_detail_data_type_t;

void sport_get_today_detail_data(sport_flash_detail_data_type_t type,uint32_t *p_dst, int unit_minute,sport_day_detail_t *p_statis);
void sport_today_detail_data_clear(void);
 #endif
